package opensocial.services;

import java.util.*;
import java.util.concurrent.*;

import opensocial.data.*;

import org.apache.shindig.auth.*;
import org.apache.shindig.common.util.*;
import org.apache.shindig.protocol.*;
import org.apache.shindig.social.opensocial.model.*;
import org.apache.shindig.social.opensocial.spi.*;

import com.google.inject.*;

@Singleton
public class PersonServiceImpl implements PersonService{

  private PersonDAO person_dao;
  
  @Inject
  public PersonServiceImpl(PersonDAO person_dao){
    this.person_dao = person_dao;
  }
  
  @Override
  public Future<RestfulCollection<Person>> getPeople( Set<UserId> userIds,
                                                      GroupId groupId, 
                                                      CollectionOptions collectionOptions, 
                                                      Set<String> fields,
                                                      SecurityToken token) throws ProtocolException {
    UserId id = (UserId)userIds.toArray()[0];
    List<Person> group = person_dao.getPeople(id,groupId);
    return ImmediateFuture.newInstance(new RestfulCollection<Person>(group));
  }

  @Override
  public Future<Person> getPerson(UserId id, 
                                  Set<String> fields,
                                  SecurityToken token) throws ProtocolException {
    
    return ImmediateFuture.newInstance(person_dao.getPerson(id));
  }
}
